﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SampleDataToolsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            bool alive = true;
            ThreadPool.QueueUserWorkItem(new WaitCallback(arg =>
            {
                UdpClient udp = new UdpClient();

                List<byte> buffs = new List<byte>();
                double t = 0.0;

                IPEndPoint point = new IPEndPoint(IPAddress.Loopback, 4466);
                Console.WriteLine("Begin Send to 4466.");
                while (alive)
                {
                    buffs.Clear();

                    buffs.AddRange(BitConverter.GetBytes(t));
                    buffs.AddRange(BitConverter.GetBytes(2.0));
                    buffs.AddRange(BitConverter.GetBytes(5.0));
                    buffs.AddRange(BitConverter.GetBytes(100.0));
                    buffs.AddRange(BitConverter.GetBytes(Math.Sin(t/100.0)));
                    t += 1.0;
                    var buff = buffs.ToArray();


                    udp.Send(buff, buff.Length, point);
                    Thread.Sleep(10);
                }
                Console.WriteLine("end Send to 4466.");
                udp.Close();
            }));

            Console.WriteLine("push any key to stop.");

            Console.ReadKey();
            alive = false;
        }


    }
}
